<?php

use Illuminate\Database\Seeder;

class AdministratorPermissionSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $permissions = [
            // 管理员
            [
                'group_name' => '管理员',
                'display_name' => '管理员列表',
                'slug' => 'administrator',
                'method' => 'GET',
                'url' => 'administrator',
            ],
            [
                'group_name' => '管理员',
                'display_name' => '管理员添加参数',
                'slug' => 'administrator.create',
                'method' => 'GET',
                'url' => 'administrator/create',
            ],
            [
                'group_name' => '管理员',
                'display_name' => '管理员添加',
                'slug' => 'administrator.store',
                'method' => 'POST',
                'url' => 'administrator',
            ],
            [
                'group_name' => '管理员',
                'display_name' => '管理员查看',
                'slug' => 'administrator.edit',
                'method' => 'GET',
                'url' => 'administrator/\d+',
            ],
            [
                'group_name' => '管理员',
                'display_name' => '管理员编辑',
                'slug' => 'administrator.update',
                'method' => 'PUT',
                'url' => 'administrator/\d+',
            ],
            [
                'group_name' => '管理员',
                'display_name' => '管理员删除',
                'slug' => 'administrator.destroy',
                'method' => 'DELETE',
                'url' => 'administrator/\d+',
            ],

            // 管理员角色
            [
                'group_name' => '管理员角色',
                'display_name' => '管理员角色列表',
                'slug' => 'administrator_role',
                'method' => 'GET',
                'url' => 'administrator_role',
            ],
            [
                'group_name' => '管理员角色',
                'display_name' => '管理员角色添加参数',
                'slug' => 'administrator_role.create',
                'method' => 'GET',
                'url' => 'administrator_role/create',
            ],
            [
                'group_name' => '管理员角色',
                'display_name' => '管理员角色添加',
                'slug' => 'administrator_role.store',
                'method' => 'POST',
                'url' => 'administrator_role',
            ],
            [
                'group_name' => '管理员角色',
                'display_name' => '管理员角色查看',
                'slug' => 'administrator_role.edit',
                'method' => 'GET',
                'url' => 'administrator_role/\d+',
            ],
            [
                'group_name' => '管理员角色',
                'display_name' => '管理员角色编辑',
                'slug' => 'administrator_role.update',
                'method' => 'PUT',
                'url' => 'administrator_role/\d+',
            ],
            [
                'group_name' => '管理员角色',
                'display_name' => '管理员角色删除',
                'slug' => 'administrator_role.destroy',
                'method' => 'DELETE',
                'url' => 'administrator_role/\d+',
            ],

            // 系统配置
            [
                'group_name' => '系统',
                'display_name' => '系统配置读取',
                'slug' => 'setting',
                'method' => 'GET',
                'url' => 'setting',
            ],
            [
                'group_name' => '系统',
                'display_name' => '系统配置保存',
                'slug' => 'setting.save',
                'method' => 'POST',
                'url' => 'setting',
            ],
            //居魔方轮播图管理
            [
                'group_name' => 'banner管理',
                'display_name' => 'banner管理',
                'slug' => 'banner_serve',
                'method' => 'GET,POST,PUT,DELETE',
                'url' => 'banner_serve.*',
            ],
            //居魔方轮播图管理
            [
                'group_name' => '经典案例管理',
                'display_name' => '经典案例管理',
                'slug' => 'classic_case_serve',
                'method' => 'GET,POST,PUT,DELETE',
                'url' => 'classic_case_serve.*',
            ],
            //720全景图库管理
            [
                'group_name' => '720全景图库内容',
                'display_name' => '720全景图库内容',
                'slug' => 'spacescheme_serve',
                'method' => 'GET,POST,PUT,DELETE',
                'url' => 'space_scheme_serve.*',
            ],
            //720全景图库管理
            [
                'group_name' => '720全景图库内容',
                'display_name' => '720全景图库内容',
                'slug' => 'spacescheme_content_serve',
                'method' => 'GET,POST,PUT,DELETE',
                'url' => 'space_scheme_content.*',
            ],
            //720全景图库管理
            [
                'group_name' => '720全景图库内容类别',
                'display_name' => '720全景图库内容类别',
                'slug' => 'spacescheme_category_serve',
                'method' => 'GET,POST,PUT,DELETE',
                'url' => 'space_scheme_content_category.*',
            ],
            //720全景图库管理
            [
                'group_name' => '设计师管理',
                'display_name' => '设计师管理',
                'slug' => 'designer_serve',
                'method' => 'GET,POST,PUT,DELETE',
                'url' => 'designer_serve.*',
            ],
        ];
        // DB::delete('delete from administrator_permissions where id = 202');

        // DB::delete('truncate table administrator_permissions');
        foreach ($permissions as $permission) {
            $exists = \App\Models\AdministratorPermission::where('slug', $permission['slug'])
                ->where('method', $permission['method'])
                ->exists();
            if ($exists) {
                continue;
            }
            \App\Models\AdministratorPermission::create([
                'display_name' => $permission['display_name'],
                'group_name' => $permission['group_name'],
                'slug' => $permission['slug'],
                'description' => $permission['description'] ?? '',
                'method' => $permission['method'],
                'url' => $permission['url'],
                'route' => $permission['route'] ?? '',
            ]);
        }
    }
}
